<div class="panel-body">
	<div class="table-responsive">
		<div class="dataTables_wrapper form-inline" id="dataTables-example_wrapper" role="grid">
			<div class="row" style="padding-bottom: 15px">
				<div class="col-sm-6">
					<div class="dataTables_length" id="dataTables-example_length">
						<select name="dataTables-example_length" class="form-control input-sm" aria-controls="dataTables-example" id="area" onchange="changearea()">
							<option value="">区/县</option>
						</select>
						<select name="dataTables-example_length" class="form-control input-sm" aria-controls="dataTables-example" id="work" onchange="changeTwon()">
							<option value="">分局</option>
						</select>
						<select name="dataTables-example_length" class="form-control input-sm" aria-controls="dataTables-example" id="wangge">
							<option value="">网格</option>
						</select>
						<!--<select name="dataTables-example_length" class="form-control input-sm"
                                aria-controls="dataTables-example" id="wangge">
                            <option value="">网格</option>
                        </select>-->
						<a class="btn btn-serch" onclick="Search()"> <i class="fa fa-search"></i> 查 询</a>
					</div>
				</div>
				<!--<div class="col-sm-6">
                    <div class="dataTables_filter" id="dataTables-example_filter" style="float: right">
                        <a class="btn btn-success" onclick="AddCustomer()"><i class="fa fa-plus"></i> 新 增 </a>
                    </div>
                </div>-->
			</div>
			<table class="table table-striped table-bordered table-hover dataTable no-footer" id="dataTables-example" aria-describedby="dataTables-example_info">
				<thead>
					<tr role="row">
						<th tabindex="0" class="sorting_asc" aria-controls="dataTables-example" style="text-align: center;width: 5%;" rowspan="1" colspan="1">序号
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 15%;" rowspan="1" colspan="1">名称
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 15%;" rowspan="1" colspan="1">部门
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 15%;" rowspan="1" colspan="1">电话
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 20%;" rowspan="1" colspan="1">邮箱
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 10%;" rowspan="1" colspan="1">区县
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 10%;" rowspan="1" colspan="1">分局
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 10%;" rowspan="1" colspan="1">网格
						</th>
					</tr>
				</thead>
				<tbody id="customerlist">

				</tbody>
			</table>
		</div>
	</div>

</div>
<div class="row">
	<div id="page" style="float: right"></div>
</div>
<script>
	$(function() {
		//加载数据
		getdata(1);
		GetArea();
	});

	//请求列表
	function getdata(page) {
		var json = {
			url: GLOBAL.URL + "/sys/user/list",
			type: 'post',
			data: {
				"page": page,
				"limit": 15,
				"countryName": $("#area").val(),
				"branchOffice": $("#work").val(),
				"guidName": $("#wangge").val()
			},
			successfn: function(data) {
				UpdateCustomerList(data.page.list);
				setPage(data.page.totalPage);
			},
			errorfn: function() {
				//ajaxUpdataTable();
				//$.ligerDialog.warn("系统繁忙，请稍候再试");
			}
		};
		ajaxdata(json);
	}
	//加载商客经理列表数据
	function UpdateCustomerList(data) {
		var listStr = "";
		if(data != null) {
			for(var i = 0; i < data.length; i++) {
				data[i].realName = data[i].realName == null ? "" : data[i].realName;
				data[i].mobile = data[i].mobile == null ? "" : data[i].mobile;
				data[i].email = data[i].email == null ? "" : data[i].email;
				data[i].countryName = data[i].countryName == null ? "" : data[i].countryName;
				data[i].branchOffice = data[i].branchOffice == null ? "" : data[i].branchOffice;
				data[i].guidName = data[i].guidName == null ? "" : data[i].guidName;
				data[i].deptName = data[i].deptName == null ? "" : data[i].deptName;
				if((i + 1) % 2 > 0) {
					listStr += '<tr class="gradeA odd">';
					listStr += '    <td style="text-align: center">' + (i + 1) + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].realName + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].deptName + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].mobile + '</td>';
					listStr += '    <td  style="text-align: left">' + data[i].email + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].countryName + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].branchOffice + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].guidName + '</td>';
					//listStr += '    <td style="text-align: center"><a onclick="EditCustomer(' + data[i].id + ')">编辑</a> <a onclick="DelCustomer(' + data[i].id + ')">删除</a></td>';
					listStr += '</tr>';
				} else {
					listStr += '<tr class="gradeA even">';
					listStr += '    <td style="text-align: center">' + (i + 1) + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].realName + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].deptName + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].mobile + '</td>';
					listStr += '    <td  style="text-align: left">' + data[i].email + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].countryName + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].branchOffice + '</td>';
					listStr += '<td style="text-align: center;">' + data[i].guidName + '</td>';
					//listStr += '    <td style="text-align: center"><a onclick="EditCustomer(' + data[i].id + ')">编辑</a> <a onclick="DelCustomer(' + data[i].id + ')">删除</a></td>';
					listStr += '</tr>';
				}
			}
		}
		$("#customerlist").html(listStr);
	}

	//查询
	function Search() {
		getdata(1);
	}

	//新增商客经理
	function AddCustomer() {
		GLOBAL.LOADURl = "Page/customermanage/customer/customer.html";
		SaveDialog("#AddCustomer", "Page/customermanage/customer/addcustomer.html", "/costomer/save", "新增商客经理");
	}
	//编辑商客经理
	function EditCustomer(ID) {
		GLOBAL.LOADURl = "Page/customermanage/customer/customer.html";
		SaveDialog("#EditCustomer", "Page/customermanage/customer/editcustomer.html", "/costomer/update", "编辑商客经理", function() {
			loadForm("#EditCustomer", "/costomer/info/" + ID);
			$("#id").val(ID);

		});
	}

	//删除商客经理
	var deleteCustomer = function(ID, dblChoseAlert) {
		$.ajax({
			type: 'get', //请求的类型
			url: GLOBAL.URL + "/costomer/delete?ids=" + ID, //请求的地址
			dataType: "json", //返会值的类型
			async: false,
			xhrFields: {
				withCredentials: true
			},
			crossDomain: true,
			success: function(datas, textStatus) { //请求成功执行的代码
				if(datas.code == 0) {
					var onlyChoseAlert = simpleAlert({
						"content": "删除成功！",
						"buttons": {
							"确定": function() {
								getdata(1);
								dblChoseAlert.close();
								onlyChoseAlert.close();
							}
						}
					});
				} else if(datas.code == "403") {
					AlertInfo("操作失败！" + datas.msg);
					window.location.href = "login.html";
				} else {
					var onlyChoseAlert = simpleAlert({
						"content": "请求失败！" + datas.msg,
						"buttons": {
							"确定": function() {
								dblChoseAlert.close();
								onlyChoseAlert.close();
							}
						}
					});
				}
			},
			error: function() {
				json.errorfn();
			}

		});
	}

	function DelCustomer(ID) {
		AlertDel(deleteCustomer, ID);
	}
	//获取区县
	function GetArea() {
		var json = {
			url: GLOBAL.URL + "/guidinfo/getAreaList",
			type: 'post',
			data: {
				"queryType": 0,
				"scope": 2
			},
			successfn: function(data) {
				SetArea(data.data);
			},
			errorfn: function() {
				//ajaxUpdataTable();
				//$.ligerDialog.warn("系统繁忙，请稍候再试");
			}
		};
		ajaxdata(json);
	}

	function SetArea(data) {
		var str = '<option value="">区/县</option>';
		for(var i = 0; i < data.length; i++) {
			str += '<option value="' + data[i].countryName + '">' + data[i].countryName + '</option>';
		}
		$("#area").html(str);
	}
	//区县点击
	function changearea() {
		if($("#area").val() == "") {
			$("#work").html('<option value="">分局</option>');
			$("#wangge").html('<option value="">网格</option>');
		} else {
			GetWork($("#area").val());
		}
	}
	//获取分局
	function GetWork(areastr) {
		var json = {
			url: GLOBAL.URL + "/guidinfo/getAreaList",
			type: 'post',
			data: {
				"area": areastr,
				"queryType": 1,
				"scope": 2
			},
			successfn: function(data) {
				SetWork(data.data);
			},
			errorfn: function() {
				//ajaxUpdataTable();
				//$.ligerDialog.warn("系统繁忙，请稍候再试");
			}
		};
		ajaxdata(json);
	}

	function SetWork(data) {
		var str = '<option value="">分局</option>';
		for(var i = 0; i < data.length; i++) {
			if(data[i] != null) {
				str += '<option value="' + data[i].branchOffice + '">' + data[i].branchOffice + '</option>';
			}
		}
		$("#work").html(str);
	}
	//分局点击
	function changeTwon() {
		if($("#area").val() == "" || $("#work").val() == "") {
			$("#wangge").html('<option value="">网格</option>');
		} else {
			Getwangge($("#area").val(), $("#work").val());
		}
	}
	//获取网格
	function Getwangge(areastr, workstr) {
		var json = {
			url: GLOBAL.URL + "/guidinfo/getAreaList",
			type: 'post',
			data: {
				"area": areastr,
				"town": workstr,
				"queryType": 2,
				"scope": 0

			},
			successfn: function(data) {
				SetWangge(data.data);
			},
			errorfn: function() {
				//ajaxUpdataTable();
				//$.ligerDialog.warn("系统繁忙，请稍候再试");
			}
		};
		ajaxdata(json);
	}

	function SetWangge(data) {
		var str = '<option value="">网格</option>';
		for(var i = 0; i < data.length; i++) {
			str += '<option value="' + data[i].gridName + '">' + data[i].gridName + '</option>';
		}
		$("#wangge").html(str);
	}
</script>